#!/usr/bin/env python
#coding=utf-8
'''
Created on Aug 19, 2010
@author: lxd
'''
from common.web import Web
import random

class QQ7xWeb(Web):      
    def __init__(self, logger, proxy='', timeout=30, interval_time=180, times=3):    
        Web.__init__(self, logger, proxy=proxy, timeout=timeout, interval_time=interval_time, times=times) 

    def getVerifyCode(self):             
        url = 'http://ptlogin2.qq.com/getimage?aid=15000101&%s' % random.random()    
        referer = 'http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&appid=15000101&hide_title_bar=1&no_verifyimg=1&s_url=http%3A%2F%2Fimgcache.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3fpara%3dizone&f_url=loginerroralert&target=top&qlogin_jumpname=jump&qlogin_param=u1%3Dhttp%3A//qzone.qq.com/new.html&ptcss=0'
        return self.fetchData(referer, url) 
        
    def login(self, name, password, verifyCode):   
        url = 'http://ptlogin2.qq.com/login?u=' + name + \
        '&p=' + password + '&verifycode=' + verifyCode + \
        '&aid=15000101&u1=http%3A%2F%2Fimgcache.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&h=1&ptredirect=1&ptlang=2052&from_ui=1&dumy=&fp=loginerroralert' 
        referer = 'http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&appid=15000101&hide_title_bar=1&no_verifyimg=1&s_url=http%3A%2F%2Fimgcache.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3fpara%3dizone&f_url=loginerroralert&target=top&qlogin_jumpname=jump&qlogin_param=u1%3Dhttp%3A//qzone.qq.com/new.html&ptcss=0'
        return self.fetchData(referer, url)      
    
    def loginApp(self, serverId): 
        referer = 'http://game.7.qq.com/index.shtml'
        url = 'http://commwebgame.qq.com/cgi-bin/CommWebGame/7X/7XLoginApp.cgi'
        data = 'sGameKind=7X&sFrom=website&sNewServerId=%s&sOldServerId=' % serverId
        return self.fetchData(referer, url, data)      
    
    def getUserPic(self, url):             
        referer = ''
        return self.fetchData(referer, url) 
